<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/3.2.47/vue.global.js"></script>
    <link rel="stylesheet" href="iconfont/1/iconfont.css">
    <link rel="stylesheet" href="iconfont/2/iconfont.css">
    <title>米家购物车</title>
</head>
<style>
    body {
        margin: auto;
        background-color: #f5f5f5ff;
    }

    a {
        text-decoration: none;
        color: #757575;
    }

    li {
        list-style: none;
        display: flex;
    }

    .box1 {
        width: 100%;
        background-color: #fff;
        border-bottom: 2px solid #ff6700;
    }

    .header {
        width: 1226px;
        margin: auto;
        height: 100px;

    }

    .header img {
        width: 48px;
        height: 48px;
        float: left;
        margin-top: 26px;
    }

    .header h2 {
        float: left;
        line-height: 100px;
        font-weight: 500;
        margin-top: 0;
        margin-left: 45px;
    }

    .header p {
        float: left;
        height: 20px;
        margin-top: 10px;
        font-size: 12px;
        line-height: 100px;
        margin-left: 15px;
        color: #757575;
    }

    .content {
        background-color: #f5f5f5ff;
        width: 1226px;
        margin: auto;
    }

    .header-right {
        float: right;
    }

    .order>a:hover {
        color: #ff6700;
    }

    .title {
        display: flex;
        width: 1226px;
        height: 70px;
        line-height: 70px;
        padding-right: 26px;
        background-color: #fff;
    }

    .choice-all {
        width: 109px;
        height: 70px;
        text-align: center;
        padding-left: 20px;
    }

    .choice-all>span {
        margin-right: 10px;
    }

    .content-img {
        width: 120px;
        height: 70px;
    }

    .content-name {
        width: 380px;
        height: 70px;
        text-align: left;
    }

    .content-price {
        width: 140px;
        height: 70px;
        padding-right: 18px;
        text-align: center;
    }

    .content-num {
        width: 150px;
        height: 70px;
        text-align: center;
    }

    .content-money {
        width: 120px;
        height: 70px;
        text-align: right;
        padding-right: 81px;
    }

    .content-delete {
        width: 80px;
        height: 70px;
        padding-left: 25px;
    }

    .icon-ziyuan {
        color: #e0e0e0;
        margin-right: 10px;
    }

    .content-goods {
        /* background-color: #fff; */
        margin-top: -16px;
        margin-left: -40px;
    }

    .list-goods {
        width: 1226px;
        height: 85px;
        padding: 15px 26px 15px 0;
        border-top: 1px solid #e0e0e0;
        background-color: #fff;
        color: #424242;
        font-size: 18px;
    }

    /* .icon-ziyuan{
        width: 110px;
        height: 85px;
        text-align: center;
        line-height: 85px;
        margin: 0;
    }
    .icon-choice-full{
        width: 110px;
        height: 85px;
        text-align: center;
        line-height: 85px;
        margin: 0;
    } */
    .check {
        width: 110px;
        height: 85px;
        text-align: center;
        line-height: 85px;
        margin: 0;
    }

    input[type=checkbox] {
        cursor: pointer;
        position: relative;
        width: 18px;
        height: 18px;
        font-size: 12px;
    }

    input[type=checkbox]::after {
        position: absolute;
        top: 0;
        color: #000;
        width: 18px;
        height: 18px;
        display: inline-block;
        visibility: visible;
        padding-left: 0px;
        text-align: center;
        content: ' ';
        border-radius: 3px
    }

    input[type=checkbox]:checked::after {
        content: "✓";
        color: #fff;
        font-size: 12px;
        font-weight: bold;
        background-color: #ff6700;
    }

    .list-img {
        width: 80px;
        height: 80px;
        padding-right: 40px;
    }

    .list-name {
        width: 380px;
        height: 85px;
        line-height: 55px;
    }

    .list-price {
        width: 140px;
        height: 85px;
        text-align: center;
        padding-right: 18px;
        line-height: 55px;
    }

    .list-num {
        width: 148px;
        height: 39px;
        border: 1px solid #e0e0e0;
    }

    .list-num input {
        width: 72px;
        height: 36px;
        border: none;
        text-align: center;
        padding: 0;
    }

    .list-num button {
        width: 38px;
        height: 38px;
        background-color: #fff;
        border: none;
        line-height: 38px;
        text-align: center;
        padding: 0;
    }

    .list-money {
        width: 120px;
        height: 85px;
        text-align: left;
        padding-left: 81px;
        line-height: 55px;
        color: #ff6700;
    }

    .icon-cuowuguanbiquxiao {
        width: 80px;
        text-align: center;
        line-height: 55px;
        margin: 0;
        border: none;
        background-color: #fff;
    }

    .total-money {
        width: 1226px;
        height: 50px;
        margin: auto;
        background-color: #fff;
    }

    .total-content {
        width: 1226px;
        height: 50px;
        padding-right: 26px;
        background-color: #fff;
    }

    .p1 {
        margin-left: 32px;
    }

    .total-left p {
        float: left;
        color: #757575;
    }

    .p3 span {
        color: #ff6700;
    }

    .p2 span {
        color: #eee;
        margin-left: 5px;
        margin-right: 5px;
    }

    .p4 {
        /* width: 100px; */
        height: 50px;
        float: right;
        margin: 0;
    }

    .p4 span {
        color: #ff6700;
        font-size: 36px;
    }

    .jiesuan {
        float: right;
        width: 200px;
        height: 50px;
        color: #b0b0b0;
        background-color: #ff6700;
        margin-right: -26px;
        text-align: center;
        line-height: 50px;
        font-size: 18px;
        margin-left: 20px;
    }

    .jiesuan a {
        color: #fff;
    }
</style>

<body>
    <div id="app">
        <div class="box1">
            <div class="header">
                <div class="header-left">
                    <img src="imgs/logo-mi2.png" alt="">
                    <h2>{{title1}}</h2>
                    <p>{{title2}}</p>
                </div>
                <div class="header-right">
                    <p><a href="">{{id}} <span class="iconfont icon-xiala"></span></a></p>
                    <p>|</p>
                    <p class="order"><a href="">{{order}}</a></p>

                </div>
            </div>
        </div>

        <div class="content">
            <div class="content-list">
                <div class="title">
                    <!-- <div class="choice-all"><span class="iconfont icon-ziyuan" id="choice-all"></span>全选</div> -->
                    <div class="choice-all"><span><input type="checkbox" class="checkbox" v-model="checkAll"></span>全选
                    </div>
                    <div class="content-img">&nbsp;</div>
                    <div class="content-name">商品名称</div>
                    <div class="content-price">单价</div>
                    <div class="content-num">数量</div>
                    <div class="content-money">小计</div>
                    <div class="content-delete">操作</div>
                </div>
                <div class="content-goods">
                    <ul>
                        <li v-for="(item,index) in goods" :key="index" class="list-goods">
                            <!-- <p class="iconfont icon-ziyuan" id="choice"></p> -->
                            <p class="check"><input type="checkbox" class="checkbox" v-model="item.checked" checked="1">
                            </p>
                            <img v-bind:src="item.img" class="list-img">
                            <p class="list-name">{{item.name}}</p>
                            <p class="list-price" id="price">{{item.price}}元</p>
                            <p class="list-num">
                                <button type="button" :disabled="item.num == 1" @click="item.num-=1">-</button>
                                <!-- <button  @click="item.num--" :disabled="item.num===1 >-</button> -->
                                <input type="text" :value="item.num" id="num">
                                <button type="button" :disabled="item.num == item.nums" @click="item.num++">+</button>
                                <!-- <button type="button" @click="item.num++" :disabled="item.num===item.limit" >+</button> -->
                            </p>
                            <p class="list-money" id="lists-money" onchange="change()">{{item.money}}元</p>
                            <!-- <p class="iconfont icon-cuowuguanbiquxiao"></p> -->
                            <p><button type="button" class="iconfont icon-cuowuguanbiquxiao"
                                    @click="del(index)"></button></p>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="total-money">
            <div class="total-content">
                <div class="total-left">
                    <p class="total-left p1">{{title3}}</p>
                    <p class="total-left p2">&nbsp;&nbsp;&nbsp;<span>|</span>&nbsp;&nbsp;&nbsp;</p>
                    <p class="total-left p3">已选择<span>{{number}}</span>件</p>
                </div>
                <div class="total-right">
                    <div class="jiesuan">
                        <a href="">去结算</a>
                    </div>
                    <p class="total-right p4">合计：<span>{{sumPrice}}</span>元</p>
                </div>
            </div>
        </div>

    </div>

    <script>
        const app = Vue.createApp({
            data() {
                return {
                    title1: "我的购物车",
                    title2: "温馨提示：产品是否购买成功，以最终下单为准哦，请尽快结算",
                    id: "2777301606",
                    order: "我的订单",
                    goods: [
                        { index: "1", choice: "", img: "imgs/xiaomi1.webp", name: "Redmi Buds 4青春版 晴雪白", price: "149", num: "1", money: "149", delete: "", checked: "true", goodid: 1001, },
                        { index: "2", choice: "", img: "imgs/xiaomi2.webp", name: "小米真无线蓝牙耳机Air2 SE 白色", price: "169", num: "1", money: "169", delete: "", checked: "true", goodid: 1002, },
                        { index: "3", choice: "", img: "imgs/xiaomi3.webp", name: "小米手环7 夜跃黑", price: "249", num: "1", money: "249", delete: "", checked: "true", goodid: 1003, },
                    ],
                    title3: "继续购物",

                }
            },
            methods: {
                // add(v){
                //     // this.goods.num=this.goods.num+v;
                //     // var val=document.querySelector("#num").value;
                //     // val=val+v;
                //     // document.querySelector("#num").innerHTML=val;
                //     console.log("jia1");
                // },
                // reduce(v){
                //     // this.goods.num=this.goods.num-v;
                //     var val=document.querySelector("#num").value;
                //     val=val-v;
                //     document.querySelector("#num").innerHTML=val;
                // },
                // money(){
                //     var price=document.querySelector("#price").value;
                //     var num=document.querySelector("#num").value;
                //     var money = price*num;
                //     document.querySelector("#lists-money").innerHTML=money;
                // },
                save() {
                    console.log(this.goods.filter((item) => item.checked));
                },
                del(id) {
                    this.goods.splice(id, 1);
                }
            },
            computed: {
                checkAll: {
                    set(a) {
                        this.goods.forEach((item) => (item.checked = a));
                    },
                    get() {
                        return (
                            this.goods.length ===
                            this.goods.filter((item) => item.checked).length
                        );
                    }
                },
                sumPrice() {
                    return this.goods.filter((item) => item.checked).reduce((pre, cur) => {
                        return pre + cur.price * cur.num
                    }, 0)
                },
                number() {
                    return (
                        this.goods.length
                    );
                },
                money() {

                },
            }
        });
        const vm = app.mount('#app');
        // let num = document.querySelector("#num").value;
        // let price = document.querySelector("#price").value;
        // function change() {
        //     money = num * price;
        //     document.querySelector("#lists-money").innerHTML = money;
        // }

        // let choiceAll=document.querySelector("#choice-all");
        // let choice=document.querySelector("#choice");
        // let index=document.querySelector("#index");

        // choiceAll.onclick=function(){
        //     this.className="iconfont icon-choice-full";
        //     choice.className="iconfont icon-choice-full";
        // }
        // choice.onclick=function(){
        //     this.className="iconfont icon-choice-full";
        // }
    </script>
</body>

</html>